The present invention relates to an electronic device having a flash memory and control method of the electronic device, and a storage medium.
Lately, portable-type electronic device (e.g., an electronic organizer, electronic notepad, electronic scheduler, or a device integrating these devices) are widely use. Since this type of device is designed to be used on the road, the device is required to maintain data even if the battery power runs out.
Meanwhile, many inventions have been proposed for erase processing of a flash memory. For instance, Motorola""s U.S. Pat. No. 5,473,569 proposes a control method in which a particular block is designated as a copy block, data in a memory block to be erased is moved to the copy block, then after all the necessary data is moved to the copy block, the memory block is erased, and the erased memory block is used as a new copy block.
This processing is performed for the following reason. In a memory such as SRAM, data can be written in byte units, and erasing data before writing is unnecessary. On the contrary, in a flash memory, a relatively large block of data (normally, 64K bytes-byte unit) must be erased before writing data in an address designated by byte units. According to the proposed invention, in a case where the memory block contains both effective data and data subjected to erasing, the effective data is temporarily saved in another memory such as SRAM or the like before the data is erased, and then the effective data is written back to the memory block.
However, in the above-described conventional art, for instance, when a file is erased, all files except the file subjected to erasing are written sequentially in a copy block having a large block size (64K bytes) in a flash memory. Therefore, an index managing effective blocks must be changed at each erase operation, requiring complicated and time consuming processing. In addition, if the available area of the memory is smaller than the file size, an erased memory block must be searched for.
The present invention is made in consideration of the above situation, and has as its object to provide an electronic device and control method thereof as well as a storage medium for erasing data stored in a flash memory at high speed with simple processing and improving an operation environment.
In order to attain the above object, the electronic device of the present invention has the following configuration.
More specifically, the present invention provides an electronic device having a flash memory, comprising: management means dividing a sector of the flash memory indicative of an erase unit into a plurality of blocks, having an area for storing code data indicative of whether data stored in each block is effective or ineffective, and having file management data for managing a file by one or a plurality of blocks; first erase means for writing an ineffective code in the area of each block constructing the file, when an erase request for erasing a file stored in the flash memory is inputted; transfer means for transferring, sector by sector, effective blocks of the sector except blocks storing an ineffective code, to a predetermined volatile memory at a predetermined timing, while maintaining a relative position of a storage address of each effective block; second erase means for erasing a sector of interest in the flash memory after transfer operation is performed by the transfer means; and write means for writing the effective blocks, which have been transferred to the volatile memory, in the erased sector while maintaining the relative position of the storage address of each effective block.
Other features and advantages of the present invention will be apparent from the following description taken in conjunction with the accompanying drawings, in which like reference characters designate the same or similar parts throughout the figures thereof.